//
//  SignInCollectionViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/24.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SignInCollectionViewCell.h"

@interface SignInCollectionViewCell ()

@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIButton *concernBtn;
@property (nonatomic, strong) UIButton *collectionBtn;
@property (nonatomic, strong) UIButton *commentBtn;
@property (nonatomic, strong) UIButton *shareBtn;

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation SignInCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    UIView *shadowBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(10), 0, ScreenX375(337), ScreenX375(338))];
    shadowBg.backgroundColor = [UIColor whiteColor];
    shadowBg.layer.cornerRadius = ScreenX375(8);
    shadowBg.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.11).CGColor;
    shadowBg.layer.shadowOffset = CGSizeMake(0, 6);
    shadowBg.layer.shadowRadius = 14;
    shadowBg.layer.shadowOpacity = 1;
    [self addSubview:shadowBg];
    
    UIView *allBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(10), 0, ScreenX375(337), ScreenX375(338))];
    allBg.backgroundColor = [UIColor whiteColor];
    allBg.layer.cornerRadius = ScreenX375(8);
    allBg.clipsToBounds = YES;
    [self addSubview:allBg];
    
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(20), ScreenX375(37), ScreenX375(37))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(18.5);
    self.headView.image = ImageWithName(@"头像1");
    [allBg addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(59), ScreenX375(22), ScreenX375(150), ScreenX375(16))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = KBlodfont(14);
    self.nameLabel.text = @"Makeup行走天涯";
    [allBg addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(59), ScreenX375(44), ScreenX375(200), ScreenX375(14))];
    self.timeLabel.textColor = REXADECIMALCOLOR(@"#888888");
    self.timeLabel.font = Kfont(12);
    self.timeLabel.text = @"行走的设计师，只为给您最好的";
    [allBg addSubview:self.timeLabel];
    
    self.concernBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(249), ScreenX375(25), ScreenX375(76), ScreenX375(28))];
    [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
    self.concernBtn.titleLabel.font = Kfont(14);
    [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
    self.concernBtn.layer.cornerRadius = ScreenX375(14);
    self.concernBtn.layer.borderWidth = 1;
    self.concernBtn.layer.borderColor = REXADECIMALCOLOR(@"#eaeaea").CGColor;
    [self.concernBtn addTarget:self action:@selector(concernAction) forControlEvents:UIControlEventTouchUpInside];
    [allBg addSubview:self.concernBtn];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(64), ScreenX375(313), ScreenX375(32))];
    self.contentLabel.text = @"英伦室内机房你上课会计师的烦恼";
    self.contentLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.contentLabel.font = Kfont(15);
    [allBg addSubview:self.contentLabel];
    
    self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(98), ScreenX375(313), ScreenX375(186))];
    self.bgView.image = [UIImage imageNamed:@"图层57"];
    self.bgView.contentMode = UIViewContentModeScaleAspectFill;
    self.bgView.layer.cornerRadius = ScreenX375(6);
    self.bgView.clipsToBounds = YES;
    [allBg addSubview:self.bgView];
    
    self.collectionBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.collectionBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    [self.collectionBtn setTitle:@" 665" forState:UIControlStateNormal];
    [self.collectionBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.collectionBtn.titleLabel.font = Kfont(14);
    self.collectionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.collectionBtn addTarget:self action:@selector(appraiseAction) forControlEvents:UIControlEventTouchUpInside];
    [allBg addSubview:self.collectionBtn];
    
    self.commentBtn = [[UIButton alloc] initWithFrame:CGRectMake((ScreenX375(337) - ScreenX375(60)) / 2, ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.commentBtn setImage:ImageWithName(@"评论 copy 2") forState:UIControlStateNormal];
    [self.commentBtn setTitle:@" 26" forState:UIControlStateNormal];
    [self.commentBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.commentBtn.titleLabel.font = Kfont(14);
    self.commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
    [allBg addSubview:self.commentBtn];
    
    self.shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(337) - ScreenX375(72), ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.shareBtn setImage:ImageWithName(@"转发") forState:UIControlStateNormal];
    [self.shareBtn setTitle:@" 19" forState:UIControlStateNormal];
    [self.shareBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.shareBtn.titleLabel.font = Kfont(14);
    self.shareBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
    [allBg addSubview:self.shareBtn];
}

- (void)setChannelListModel:(ChannelListModel *)channelListModel {
    _channelListModel = channelListModel;
    
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:channelListModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    
    [self.collectionBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.zanNum] forState:UIControlStateNormal];
    [self.commentBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.appraiseNum] forState:UIControlStateNormal];
    [self.shareBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.shareNum] forState:UIControlStateNormal];
    self.nameLabel.text = channelListModel.userName;
    self.contentLabel.text = channelListModel.proName;
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:channelListModel.proPic] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.headView sd_setImageWithURL:[NSURL URLWithString:channelListModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.timeLabel.text = [HttpManager getTime:[HttpManager TimeStamp:channelListModel.createTime]];
    
    if ([channelListModel.isZan integerValue]) {
        [self.collectionBtn setImage:ImageWithName(@"已点赞") forState:UIControlStateNormal];
    }else {
        [self.collectionBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    }
    
    if ([channelListModel.isFollow integerValue]) {
        [self.concernBtn setTitle:@"已关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#212121") forState:UIControlStateNormal];
        [self.concernBtn setImage:nil forState:UIControlStateNormal];
    }else {
        [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
        [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    }
}

- (void)concernAction {
    if (_concernClick) {
        _concernClick();
    }
}

- (void)appraiseAction {
    if (_appraiseClick) {
        _appraiseClick();
    }
}

- (void)commentAction {
    if (_commentClick) {
        _commentClick();
    }
}

- (void)shareAction {
    if (_shareClick) {
        _shareClick();
    }
}

@end
